<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.lmpop.trade.ti_gift.*"%>
<%@page import="java.util.*"%>
<%@page import="com.lmpop.frame.util.PageTools"%>
<%@page import="com.lmpop.trade.ts_category.Ts_categoryInfo"%>
<%

	request.setCharacterEncoding("UTF-8");
	Hashtable ti_gift = new Hashtable();
	String req_gift_name = "";
	String req_gift_type = "";
	String req_state_code = "";
	String cust_id = "";

	if (request.getParameter("req_gift_name") != null	&& !request.getParameter("req_gift_name").equals("")) {
		req_gift_name = request.getParameter("req_gift_name");
		ti_gift.put("gift_name", req_gift_name);
	}
	if (request.getParameter("cust_id") != null	&& !request.getParameter("cust_id").equals("")) {
		cust_id = request.getParameter("cust_id");
		ti_gift.put("cust_id", cust_id);
	}

	if (request.getParameter("req_gift_type") != null	&& !request.getParameter("req_gift_type").equals("")) {
		req_gift_type = request.getParameter("req_gift_type");
		ti_gift.put("gift_type", req_gift_type);
	}

	if (request.getParameter("req_state_code") != null && !request.getParameter("req_state_code").equals("")) {
		req_state_code = request.getParameter("req_state_code");
		ti_gift.put("state_code", req_state_code);
	}


	Ti_giftInfo ti_giftInfo = new Ti_giftInfo();
	String iStart = "0";
	int limit = 20;
	if (request.getParameter("iStart") != null)	iStart = request.getParameter("iStart");
	List list = ti_giftInfo.getListByPage(ti_gift, Integer.parseInt(iStart), limit);
	int counter = ti_giftInfo.getCountByObj(ti_gift);
	String pageString = new PageTools().getGoogleToolsBar(counter,"giftindex.jsp?iStart=", Integer.parseInt(iStart), limit);
			
	Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
	Map catMap = ts_categoryInfo.getCatClassMap("2");
%>
<html>
	<head>

		<title>礼品管理</title>
		<link href="/program/admin/index/css/style.css" rel="stylesheet"
			type="text/css">
		<script type="text/javascript" src="/js/commen.js"></script>
		<script type="text/javascript" src="index.js"></script>
	</head>

	<body>
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td width="90%">
					<h1>
						礼品管理
					</h1>
				</td>
				<td>
					<a href="addInfo.jsp?cust_id=<%=cust_id%>"><img	src="/program/admin/index/images/post.gif" />
					</a>
				</td>
			</tr>
		</table>

		<form action="giftindex.jsp" name="indexForm" method="get">

			<table width="100%" cellpadding="0" cellspacing="0" class="dl_su">
				<tr>
					<td align="left">


						礼品名称:
						<input name="req_gift_name" id="gift_name" type="text" />
						 <input name="cust_id" id="cust_id" type="hidden" value="<%=cust_id%>"/>

						<input name="searchInfo" type="button" value="查询"	onclick="return search();" />
					</td>
				</tr>
			</table>

			<table width="100%" cellpadding="0" cellspacing="0" border="0"
				class="tablehe">
				<tr>
					<td><%=pageString%></td>
				</tr>
			</table>

			<%
				int listsize = 0;
				if (list != null && list.size() > 0) {
					listsize = list.size();
			%>

			<table width="100%" cellpadding="0" cellspacing="0" border="0"
				class="dl_bg">
				<tr>
					<td width="90%">
						<input type="button" name="delInfo" onclick="delIndexInfo()"
							value="删除" class="buttab" />
					</td>
					<td>
						总计:<%=counter%>条
					</td>
				</tr>
			</table>

			<table width="100%" cellpadding="1" cellspacing="1" class="listtab"
				border="0">
				<tr>
					<th width="5%" align="center">
						<input type="checkbox" name="checkall" id="checkall"
							onclick="selectAll()">
					</th>

					<th>
						礼品名称
					</th>

					

					<th>
						礼品分类
					</th>

				 
					<th>
						状态
					</th>

					<th>
						操作时间
					</th>
					<th width="10%">
						修改
					</th>
					<th width="10%">
						删除
					</th>
				</tr>


				<%
					for (int i = 0; i < list.size(); i++) {
							Hashtable map = (Hashtable) list.get(i);
							String gift_id = "", gift_name = "", gift_type = "", good_id = "", class_attr = "", gift_no = "", stock_num = "", state_code = "", in_date = "", user_id = "";
							String str="";
							if (map.get("gift_id") != null)
								gift_id = map.get("gift_id").toString();
							if (map.get("gift_name") != null)
								gift_name = map.get("gift_name").toString();
							if (map.get("gift_type") != null)
								gift_type = map.get("gift_type").toString();
							if (map.get("good_id") != null)
								good_id = map.get("good_id").toString();
							if (map.get("class_attr") != null)
								class_attr = map.get("class_attr").toString();
							if (map.get("gift_no") != null)
								gift_no = map.get("gift_no").toString();
							if (map.get("stock_num") != null)
								stock_num = map.get("stock_num").toString();
							if (map.get("state_code") != null)
								state_code = map.get("state_code").toString();
							if (map.get("in_date") != null)
								in_date = map.get("in_date").toString();
							if (in_date.length() > 19)
								in_date = in_date.substring(0, 19);
							if (map.get("user_id") != null)
								user_id = map.get("user_id").toString();
							
							if (!class_attr.equals("")) {
									String catIds[] = class_attr.split("\\|");
									for (String catId : catIds) {
										if (catMap != null) {
											if (catMap.get(catId) != null) {
												str+=catMap.get(catId).toString() + " ";
											}
							
										}
									}
								}	
				%>

				<tr>
					<td width="5%" align="center">
						<input type="checkbox" name="checkone<%=i%>" id="checkone<%=i%>"
							value="<%=gift_id%>" />
					</td>

					<td><%=gift_name%></td>					

					<td><%=str %></td>

					<td>
					<%
							if (state_code.equals("1") ) {
										out.print("可用");
							} else {
										out.print("不可用");
							}
						%>
					</td>

					<td><%=in_date%></td>

					<td width="10%">
						<a href="updateInfo.jsp?gift_id=<%=gift_id%>"><img
								src="/program/admin/images/edit.gif" title="编辑" />
						</a>
					</td>
					<td width="10%">
						<a href="javascript:deleteOneInfo('<%=gift_id%>','5610');"><img
								src="/program/admin/images/delete.gif" title="删除" />
						</a>
					</td>
				</tr>

				<%
					}
				%>

			</table>

			<table width="100%" cellpadding="0" cellspacing="0" border="0"
				class="dl_bg">
				<tr>
					<td width="90%">
						<input type="button" name="delInfo" onclick="delIndexInfo()" value="删除" class="buttab" />
					</td>
					<td>
						总计:<%=counter%>条
					</td>
				</tr>
			</table>
			<table width="100%" cellpadding="0" cellspacing="0" border="0"
				class="tablehe">
				<tr>
					<td><%=pageString%></td>
				</tr>
			</table>

			<%
				}
			%>

			<input type="hidden" name="listsize" id="listsize"
				value="<%=listsize%>" />
			<input type="hidden" name="pkid" id="pkid" value="" />
			<input type="hidden" name="bpm_id" id="bpm_id" value="5610" />
		</form>
	</body>

</html>
